def calculate_animal_num(head: int, leg: int):
    rabbit = (leg - head * 2) // 2
    chicken = head - rabbit
    temp_leg_num = 4 * rabbit + 2 * chicken
    if temp_leg_num == leg and rabbit >= 0 and chicken >= 0:
        return True, rabbit, chicken
    else:
        return False, 0, 0


while True:
    print("~~~========鸡兔同笼问题处理========~~~")
    while True:
        head_num = input("请输入头的数量：")
        if head_num.isdigit():
            head_num = int(head_num)
            break
        else:
            print("请输入数字，重新输入")
    while True:
        leg_num = input("请输入脚的数量：")
        if leg_num.isdigit():
            leg_num = int(leg_num)
            break
        else:
            print("请输入数字，重新输入")
    if head_num > leg_num:
        print("数量有误，请重新输入")
    else:
        status, rabbit, chicken = calculate_animal_num(head_num, leg_num)
        if status:
            print("{}个头，{}条腿，经过计算，答案是：{}只兔子，{}只鸡".format(head_num, leg_num, rabbit, chicken))
        else:
            print("经过计算，{}个头，{}条腿，不符合四腿兔子二脚鸡的设定".format(head_num, leg_num))
